/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.eftimoff.empty.slice;

import com.eftimoff.empty.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    public static final String TAG = MainAbilitySlice.class.getName();

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        (findComponentById(ResourceTable.Id_btn_case_1)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_2)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_3)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_4)).setClickedListener(this);
        (findComponentById(ResourceTable.Id_btn_case_5)).setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_btn_case_1:
                launchTestAbility(1);
                break;
            case ResourceTable.Id_btn_case_2:
                launchTestAbility(2);
                break;
            case ResourceTable.Id_btn_case_3:
                launchTestAbility(3);
                break;
            case ResourceTable.Id_btn_case_4:
                launchTestAbility(4);
                break;
            case ResourceTable.Id_btn_case_5:
                launchTestAbility(5);
                break;

            default:
                break;
        }
    }

    private void launchTestAbility(int testCase) {
        Intent intent1 = new Intent();
        Operation operation = new Intent.OperationBuilder().withBundleName("com.eftimoff.empty")
            .withAbilityName("com.eftimoff.empty.TestAbility")
            .build();
        intent1.setOperation(operation);
        intent1.setParam("Case", testCase);
        startAbility(intent1);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
